package com.pets.web.controller.admin;


import com.pets.common.core.controller.BaseController;
import com.pets.common.core.domain.AjaxResult;
import com.pets.common.core.page.TableDataInfo;
import com.pets.common.utils.SecurityUtils;
import com.pets.web.entity.PetsPlatform;
import com.pets.web.entity.PetsPlatformShare;
import com.pets.web.service.IPetsPlatformService;
import com.pets.web.service.IPetsPlatformShareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 平台分享 前端控制器
 * </p>
 *
 * @author zhurenwang
 * @since 2024-05-26
 */
@RestController
@RequestMapping("/share")
public class PetsPlatformShareController extends BaseController {

    @Autowired
    private IPetsPlatformShareService petsPlatformShareService;

    @GetMapping("/list")
    public TableDataInfo list(PetsPlatformShare petsPlatformShare){
        startPage();
        if (SecurityUtils.isAdmin(SecurityUtils.getUserId())) {
            petsPlatformShare.setSysUserId(null);
        } else {
            petsPlatformShare.setSysUserId(SecurityUtils.getUserId());
        }
        List<PetsPlatformShare> list = petsPlatformShareService.list(petsPlatformShare);
        return getDataTable(list);
    }

    @PostMapping()
    public AjaxResult add(@RequestBody PetsPlatformShare petsPlatformShare){
        return success(petsPlatformShareService.add(petsPlatformShare));
    }

    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable Integer id){
        return success(petsPlatformShareService.deleteById(id));
    }

    @GetMapping("/{id}")
    public AjaxResult get(@PathVariable Integer id){
        return success(petsPlatformShareService.getById(id));
    }

    @PutMapping()
    public AjaxResult edit(@RequestBody PetsPlatformShare petsPlatformShare){
        return success(petsPlatformShareService.updateById(petsPlatformShare));
    }

    @GetMapping("/getAll")
    public AjaxResult getAll(Integer goodsId){
        return success(petsPlatformShareService.getAll(goodsId));
    }
}
